from email import message
import json
import aiohttp
from sqlalchemy import JSON

from .api_urls import APIUrls
from . import auth as auth_tools


async def get_request(
    url: str,
    headers: dict | None = None,
    data: dict | None = None,
):
    async with aiohttp.ClientSession() as session:
        async with session.get(
            url=url,
            headers=headers,
            json=data,
        ) as response:
            json_data = await response.json()

            return json_data


async def post_request(
    url: str,
    headers: dict | None = None,
    data: dict | None = None,
):
    async with aiohttp.ClientSession() as session:
        async with session.post(
            url=url,
            headers=headers,
            json=data,
        ) as response:
            json_data = await response.json()

            return json_data


async def get_ads_list_request(chat_id: int) -> list[str]:

    url = APIUrls.get_ads_list
    token = await auth_tools.get_token(chat_id)
    headers = {"X-Auth-Token": token}

    response = await get_request(url, headers)

    return response["message"]
    